//
//  MyInfoTool.m
//  Thinkape-iOS
//
//  Created by admin on 16/5/25.
//  Copyright © 2016年 TIXA. All rights reserved.
//http://27.115.23.126:5032/Ashx/MobileNew.ashx?ac=UserInfo&u=1&pid=410402&pk=1

#import "MyInfoTool.h"
#import "MJExtension.h"
#import "RequestCenter.h"
#import "DataManager.h"

@implementation MyInfoTool

+ (void)getTestDataWithSuccessfulBlock:(SuccessfulBlock )block
{
//    MyInfoModel *model0 = [[MyInfoModel alloc]init];
//    //第一组：
//    NSMutableArray *array0 = [[NSMutableArray alloc]init];
//    NSMutableArray *rootArray = [NSMutableArray new];
//    model0.headInfo = @"头像";
//    [array0 addObject:model0];
//    [rootArray addObject:array0];
//    //第二组
//    
//    
//    NSArray *array1 = @[
//                        @{@"name":@"用户名",@"detail":@"系统管理员"},
//                        @{@"name":@"账号",@"detail":@"Admin"},
//                        @{@"name":@"邮箱",@"detail":@"zyl1881@163.com"}
//                        ];
//    NSMutableArray *array11 = [NSMutableArray new];
//    
//    for (int i = 0; i < array1.count; i++) {
//        MyInfoModel *model1 = [[MyInfoModel alloc]init];
//        model1.headInfo = [array1[i] objectForKey:@"name"];
//        model1.detailInfo = [array1[i] objectForKey:@"detail"];
//        [array11 addObject:model1];
//        
//    }
//    [rootArray addObject:array11];
//    //第三组：
//    
//    NSMutableArray *array22 = [NSMutableArray new];
//    NSArray *array2 = @[
//                        @{@"name":@"职位",@"detail":@"开发"},
//                        @{@"name":@"部门",@"detail":@"开发组"},
//                        ];
//    for(int i = 0; i < array2.count; i++)
//    {
//        MyInfoModel *model3 = [[MyInfoModel alloc]init];
//        model3.headInfo = [array2[i] objectForKey:@"name"];
//        model3.detailInfo = [array2[i] objectForKey:@"detail"];
//        
//        [array22 addObject:model3];
//        
//    }
//    [rootArray addObject:array22];
//    block(rootArray,@{},@"");
//    
}


+ (void)getMyInformationWithSuccessfulBlock:(SuccessfulBlock )block
{
 //http://27.115.23.126:5032/Ashx/MobileNew.ashx?ac=UserInfo&u=1&pid=410402&pk=1
    //ac=GetInfoList&u=%@&pi=%d&ps=20
    NSString *urlStr = [NSString stringWithFormat:@"ac=UserInfo&u=%@&pid=410402&pk=1",[DataManager shareManager].uid];
    
    
    [RequestCenter GetRequest:urlStr parameters:nil success:^(NSURLSessionDataTask *operation, NSDictionary *responseObject) {
        
        //左边item
        NSArray *rootArray = [[responseObject objectForKey:@"msg"] objectForKey:@"data"];
        
        NSArray *valueArr = [rootArray[0] objectForKey:@"info"];
        //modelArray:装着model的数组：
        NSMutableArray  *modelArray = [MyInfoModel objectArrayWithKeyValuesArray:[valueArr[0] objectForKey:@"field"]];
        for (MyInfoModel *model in modelArray) {
            if ([model.IsSave isEqualToString:@"False"]) {
                [modelArray removeObject:model];
            }
        }
        //model数组对应的右边取值：
        NSDictionary *valueDict = [valueArr[1] objectForKey:@"value"][0];
        //部门：
        NSArray *depArray = [rootArray[1] objectForKey:@"info"];
        NSArray *depModelArray = [DepartmentModel objectArrayWithKeyValuesArray:depArray];
     
     
        NSString *depStr = @"";
        
        for (DepartmentModel *model in depModelArray) {
            depStr = [depStr stringByAppendingFormat:@"%@,",model.text];
            
        }
        depStr = [depStr substringToIndex:depStr.length - 1];
        
        block (modelArray,valueDict,depStr);
        
        [SVProgressHUD dismiss];
        
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        
        [SVProgressHUD showErrorWithStatus:@"网络出现问题，请稍后再试"];
    }];

}




@end
